﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WS.EKA.FJYCM.Business.DAL;
using WS.EKA.FJYCM.Business.Model;
using System.Data;
using WS.EKA.FJYCM.Utilities;
using Oracle.DataAccess.Client;

namespace WS.EKA.FJYCM.Business
{
    public class HelpDeskAccess
    {
        static IDB db = DBFactory.CreateARDB();

        public static List<Hpd_help_desk> GetSJUnclosedEvent()
        {
            DataTable sjEvents = db.ExecuteDataTable(
                "select Department,Business_system from hpd_Help_Desk where status < 5 and Contact_Company = '福建省烟草专卖局'");

            return sjEvents.ToList<Hpd_help_desk>();
        }

        public static int GetEventCountByDeptAndSysName(string sysName, string deptName)
        {
            OracleParameter systemName = new OracleParameter("SystemName", sysName);
            OracleParameter departmentName = new OracleParameter("DeptName", deptName);

            var eventCount = db.ExecuteDataTable(
                "select count(*) from hpd_help_desk where status < 5 and contact_company = '福建省烟草专卖局' and business_system = :SystemName and department = :DeptName",
                systemName, departmentName);

            return Convert.ToInt32(eventCount.Rows[0][0]);
        }

        public static int GetEventCountBySysName(string sysName)
        {
            var list = GetSJUnclosedEvent();
            var departments = Config.DepartmentNames;
            return list.Where(x => x.Business_System == sysName && departments.Contains(x.Department)).Count();
        }
    }
}
